package com.one.controller;


import com.one.dto.Result;
import com.one.entity.SysClassEntity;
import com.one.entity.SysCollegeEntity;
import com.one.service.SysClassService;
import com.one.service.SysCollegeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @since 2021-10-11
 */
@RestController
@RequestMapping("/class")
public class SysClassController {
    private final SysClassService sysClassService;
    public SysClassController(SysClassService sysClassService) {
        this.sysClassService=sysClassService;
    }
    //添加班级
    @ApiOperation(value = "增加班级", notes = "增加班级")
    @PostMapping("/insertClass")
    public Result insertClass(@RequestBody(required = false) SysClassEntity sysClassEntity){
        if(selectClassByCodeAndName(sysClassEntity).getData()!=null){
            return Result.error().message("该学院已经存在了");
        }
        return sysClassService.insertClass(sysClassEntity);
    }
    //根据班级名称/编号查询班级
    @ApiOperation(value = "根据班级名称/编号查询班级", notes = "根据班级名称/编号查询班级")
    @PostMapping("/selectClassByCodeAndName")
    public Result selectClassByCodeAndName(@RequestBody(required = false) SysClassEntity sysClassEntity){
        return sysClassService.selectClassByCodeAndName(sysClassEntity);
    }
    //删除班级
    @ApiOperation(value = "删除班级", notes = "删除班级")
    @PostMapping("/deleteClass")
    public Result deleteClass(@RequestBody(required = false) SysClassEntity sysClassEntity){
        if (sysClassEntity.getCode()==null){
            return Result.error().message("班级的编号不能为空");
        }
        return sysClassService.deleteClass(sysClassEntity);
    }
    //修改班级信息
    @ApiOperation(value = "修改班级信息",notes = "修改班级信息")
    @PostMapping("/updateClass")
    public Result updateClass(@RequestBody(required = false) SysClassEntity sysClassEntity){
        return sysClassService.updateClass(sysClassEntity);
    }
    //查询班级的信息
    @ApiOperation(value = "查询学院的信息", notes = "查询学院的信息")
    @PostMapping("/selectClass")
    public Result selectClass(@RequestBody(required = false) SysClassEntity sysClassEntity){
        return sysClassService.selectClass(sysClassEntity);
    }
}

